/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewAirplineDialog.java
 *
 * Created on 8.12.2011, 13:34:15
 */
package view;

import data.model.Airline;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import logic.business.DataEditor;
import logic.business.exceptions.MalformedDataException;

/**
 *
 * @author zhenia
 */
public class NewAirplaneDialog extends javax.swing.JDialog {

    private boolean result;
    private DataEditor dataEditor;

    /** Creates new form NewAirplineDialog */
    NewAirplaneDialog(DataEditor de) {
        dataEditor = de;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        seatsLabel = new javax.swing.JLabel();
        modelLabel = new javax.swing.JLabel();
        seats = new javax.swing.JTextField();
        cancel = new javax.swing.JButton();
        ok = new javax.swing.JButton();
        consumptionLabel1 = new javax.swing.JLabel();
        consumptionLabel2 = new javax.swing.JLabel();
        AvgConsumption = new javax.swing.JTextField();
        minConsumption = new javax.swing.JTextField();
        MaxConsumption = new javax.swing.JTextField();
        consumptionLabel3 = new javax.swing.JLabel();
        capacityLabel1 = new javax.swing.JLabel();
        capacity = new javax.swing.JTextField();
        model = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("New Airpline");

        seatsLabel.setText("Seats");
        seatsLabel.setName("seatsLabel"); // NOI18N

        modelLabel.setText("Model");
        modelLabel.setName("modelLabel"); // NOI18N

        seats.setName("seats"); // NOI18N

        cancel.setText("Cancel");
        cancel.setName("cancel"); // NOI18N
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });

        ok.setText("OK");
        ok.setName("ok"); // NOI18N
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });

        consumptionLabel1.setText("Avg consumption");
        consumptionLabel1.setName("consumptionLabel1"); // NOI18N

        consumptionLabel2.setText("Min consumption");
        consumptionLabel2.setName("consumptionLabel2"); // NOI18N

        AvgConsumption.setName("AvgConsumption"); // NOI18N

        minConsumption.setName("minConsumption"); // NOI18N

        MaxConsumption.setName("MaxConsumption"); // NOI18N

        consumptionLabel3.setText("Max consumption");
        consumptionLabel3.setName("consumptionLabel3"); // NOI18N

        capacityLabel1.setText("Fuel Capacity");
        capacityLabel1.setName("capacityLabel1"); // NOI18N

        capacity.setName("capacity"); // NOI18N

        model.setName("model"); // NOI18N

        jLabel1.setText("Gal/100miles");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Gal/100miles");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("Gal/100miles");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText("Gallons");
        jLabel4.setName("jLabel4"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(ok)
                        .addGap(18, 18, 18)
                        .addComponent(cancel)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(capacityLabel1)
                            .addComponent(seatsLabel)
                            .addComponent(modelLabel)
                            .addComponent(consumptionLabel1)
                            .addComponent(consumptionLabel2)
                            .addComponent(consumptionLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(MaxConsumption)
                            .addComponent(minConsumption)
                            .addComponent(AvgConsumption)
                            .addComponent(model)
                            .addComponent(seats, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE)
                            .addComponent(capacity, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGap(200, 200, 200))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(modelLabel)
                    .addComponent(model, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(seatsLabel)
                    .addComponent(seats, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(capacityLabel1)
                    .addComponent(capacity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(consumptionLabel1)
                    .addComponent(AvgConsumption, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(consumptionLabel3)
                            .addComponent(MaxConsumption, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(consumptionLabel2)
                            .addComponent(minConsumption, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3)))
                .addGap(97, 97, 97)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ok)
                    .addComponent(cancel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed

        this.result = false;
        this.dispose();
        // TODO add your handling code here:
}//GEN-LAST:event_cancelActionPerformed

    private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed

        try {

            if (model.getText().isEmpty() || seats.getText().isEmpty() || AvgConsumption.getText().isEmpty() || MaxConsumption.getText().isEmpty() || minConsumption.getText().isEmpty() || capacity.getText().isEmpty()) {
                JOptionPane.showMessageDialog(this,
                        "Fill in all parameters",
                        "Warning",
                        JOptionPane.WARNING_MESSAGE);

            } else {
                dataEditor.addNewAirplane(model.getText().toLowerCase(), model.getText(),
                        seats.getText(), AvgConsumption.getText(), MaxConsumption.getText(), minConsumption.getText(), capacity.getText());
                this.result = true;
                this.dispose();
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,
                    "Some input has wrong parameters",
                    "Warning",
                    JOptionPane.WARNING_MESSAGE);
        }



}//GEN-LAST:event_okActionPerformed

    boolean execute() {
        this.setVisible(true); // прорисовать дочернее окно; в данном месте выполнение программы приостановится, ожидая окончания работы пользователя (в нашем случае - функции dispose())
        return this.result;
    }
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AvgConsumption;
    private javax.swing.JTextField MaxConsumption;
    private javax.swing.JButton cancel;
    private javax.swing.JTextField capacity;
    private javax.swing.JLabel capacityLabel1;
    private javax.swing.JLabel consumptionLabel1;
    private javax.swing.JLabel consumptionLabel2;
    private javax.swing.JLabel consumptionLabel3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField minConsumption;
    private javax.swing.JTextField model;
    private javax.swing.JLabel modelLabel;
    private javax.swing.JButton ok;
    private javax.swing.JTextField seats;
    private javax.swing.JLabel seatsLabel;
    // End of variables declaration//GEN-END:variables

    DataEditor getDataEditor() {
        return this.dataEditor;
    }
}
